#ifndef __C_CROSSFIRE_DEVICEENGINE_H_
#define __C_CROSSFIRE_DEVICEENGINE_H_

#include "IDeviceEngine.h"

#include "CTimer.h"
#include "CWindow.h"
#include "CSettings.h"
#include "CLog.h"
#include "CDrawRenderer.h"
#include "CInput.h"
#include "CSceneManager.h"

namespace cfe
{

class CDeviceEngine : public ICF_DeviceEngine
{
private:
	ICF_Timer* m_timer;
	ICF_Window* m_window;
	ICF_Log* m_log;
	ICF_Settings* m_settings;
	ICF_DrawRenderer* m_render;
	ICF_Input* m_input;
	ICF_SceneManager* m_smg;
	void* m_happ;
public:
	CDeviceEngine(void* hApp) : m_happ(hApp)
	{
		m_timer = NULL;
		m_window = NULL;
		m_log = NULL;
		m_render = NULL;
		m_settings = NULL;
		m_input = NULL;
		m_smg = NULL;
	};

	void Destroy()
	{
		delete m_timer;
		delete m_window;
		delete m_log;
		delete m_render;
		delete m_settings;
		delete m_input;
		delete m_smg;
		delete this;
	};

	ICF_Timer* getTimerObject()
	{
		if(!m_timer)
			m_timer = new CTimer();
		return m_timer;
	}

	ICF_Settings* getSettingsObject()
	{
		return CSettings::getInstance();
	}

	ICF_Window* getWindowObject()
	{
		if(!m_window)
		{
			m_window = new CWindow((HINSTANCE)m_happ);
			m_window->Initialize();
			m_window->Show();
		}
		return m_window;
	}

	ICF_Log* getLogObject(const char* filename = STD_LOG_NAME)
	{
		if(!m_log)
		{
			m_log = CLog::getLogInstance();
			m_log->BeginLogging(filename);
		}
		return m_log;
	}

	ICF_DrawRenderer* getDrawRenderer()
	{
		if(!m_render)
			m_render = new CDrawRenderer();
		//m_render->Initialize(getWindowObject()->GetHandle());
		return m_render;
	}

	ICF_SceneManager* getSceneManager()
	{
		if(!m_smg)
			m_smg = new CSceneManager(getDrawRenderer());
		return m_smg;
	}

	ICF_Input* getInput()
	{
		if(!m_input)
			m_input = new CInput((HINSTANCE)m_happ);
		return m_input;
	}
};

};

#endif